'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.update = exports.updateRaw = exports.updateNoFixPath = undefined;

var _immutabilityHelper = require('immutability-helper');

var _immutabilityHelper2 = _interopRequireDefault(_immutabilityHelper);

var _genUpdater = require('./genUpdater');

var _get = require('lodash/get');

var _get2 = _interopRequireDefault(_get);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var updateNoFixPath = exports.updateNoFixPath = function updateNoFixPath(target, updater) {
    return (0, _immutabilityHelper2.default)(target, (0, _genUpdater.genUpdater)(updater));
};
var updateRaw = exports.updateRaw = _immutabilityHelper2.default;
var update = exports.update = function update(target, updater) {
    var keys = (0, _genUpdater.getUpdaterKeys)(updater);
    var key = void 0;
    var _target = target;
    for (var i = 0, il = keys.length; i < il; i++) {
        key = keys[i];
        if (typeof (0, _get2.default)(target, key) === 'undefined') {
            _target = (0, _immutabilityHelper2.default)(_target, (0, _genUpdater.getFixLack)(key));
        }
    }
    return (0, _immutabilityHelper2.default)(_target, (0, _genUpdater.genUpdater)(updater));
};

exports.default = update;